package me.zhengjie.inter.rest;

import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.RequiredArgsConstructor;
import me.zhengjie.annotation.Log;
import me.zhengjie.aop.annotation.BisLog;
import me.zhengjie.business.domain.Zhsq;
import me.zhengjie.business.service.ZhsqService;
import me.zhengjie.business.service.dto.SnryQueryCriteria;
import me.zhengjie.business.service.dto.ZhsqDto;
import me.zhengjie.business.service.dto.ZhsqQueryCriteria;
import me.zhengjie.inter.service.MpZhsqService;
import me.zhengjie.utils.PageUtil;
import me.zhengjie.utils.SecurityUtils;
import org.springframework.data.domain.Pageable;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletRequest;

/**
 * @author xiahongbo
 * @date 2022-07-10
 **/
@RestController
@RequiredArgsConstructor
@Api(tags = "移动端照护申请管理")
@RequestMapping("/mp/zhsq")
public class MpZhsqController {

    private final MpZhsqService mpZhsqService;

    @GetMapping
    @ApiOperation("移动端查询居家照护申请")
    public ResponseEntity<Object> queryZhsq(ZhsqQueryCriteria criteria, Pageable pageable) {
        criteria.setBisUserId(SecurityUtils.getCurrentUserId());
        criteria.setSbgs(null);
        return new ResponseEntity<>(PageUtil.toMpContent(mpZhsqService.queryAll(criteria, pageable)), HttpStatus.OK);
    }

    @PostMapping
    @Log("移动端新增居家照护申请")
    @ApiOperation("移动端新增居家照护申请")
    public ResponseEntity<Object> createZhsq(@Validated @RequestBody Zhsq resources, @RequestParam String ids, HttpServletRequest request){

        //bisLogService.save(resources.getBisZhsqId(), "新增居家照护申请", "me.zhengjie.business.rest.ZhsqController.createZhsq()", request);
        return new ResponseEntity<>(PageUtil.toMpContent(mpZhsqService.create(resources, ids)), HttpStatus.OK);
    }

    @PutMapping
    @Log("移动端新增居家照护申请")
    @ApiOperation("移动端新增居家照护申请")
    public ResponseEntity<Object> updateZhsq(@Validated @RequestBody Zhsq resources, @RequestParam String ids, HttpServletRequest request){

        //bisLogService.save(resources.getBisZhsqId(), "新增居家照护申请", "me.zhengjie.business.rest.ZhsqController.createZhsq()", request);
        return new ResponseEntity<>(PageUtil.toMpContent(mpZhsqService.updateZhsq(resources, ids)), HttpStatus.OK);
    }

    @GetMapping(value = "/queryDyqx")
    @ApiOperation("移动端查询查询待遇期限")
    public ResponseEntity<Object> queryDyqx(@RequestParam Long id) {
        return new ResponseEntity<>(PageUtil.toMpContent(mpZhsqService.queryDyqx(id)), HttpStatus.OK);
    }

    @GetMapping(value = "/checkCreate")
    @ApiOperation("移动端新增居家照护校验")
    public ResponseEntity<Object> checkCreate(@RequestParam String sfzh) {
        return new ResponseEntity<>(PageUtil.toMpContent(mpZhsqService.checkCreate(sfzh)), HttpStatus.OK);
    }

    @GetMapping(value = "/checkCbInfo")
    @ApiOperation("移动端查询校验参保信息")
    public ResponseEntity<Object> checkCbInfo(@RequestParam String sfzh) {
        return new ResponseEntity<>(PageUtil.toMpContent(mpZhsqService.checkCbInfo(sfzh)), HttpStatus.OK);
    }
}
